package com.object_;

public class ToString_ {
    public static void main(String[] args) {
        /*
        Object的toString() 源码
        (1)getClass().getName() 类的全类名（包名+类名）
        (2) Integer.toHexString(hashCode()) 将对象的hashcode值转成16进制字符串
         public String toString() {
            return getClass().getName() + "@" + Integer.toHexString(hashCode());
        }
         */

        Monster monster = new Monster("小妖怪","巡山",1000);
        System.out.println(monster.toString());
    }
}
class Monster{
    private String name;
    private String job;
    private double salary;

    public Monster(String name, String name1, double salary) {
        this.name = name;
        this.name = name1;
        this.salary = salary;
    }

    //重写toString方法，输出对象属性

    @Override
    public String toString() { //重写后，一般是把对象的属性输出
        return "Monster{" +
                "name='" + name + '\'' +
                ", job='" + job + '\'' +
                ", salary=" + salary +
                '}';
    }
}
